package org.ushio.nchu_22201402.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.ushio.common_module.entity.CSSCR;
import org.ushio.nchu_22201402.service.Admin_UpdateSalaryService;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping(value = "/AdminCS")
public class Admin_UpdateSalaryController {

    @Autowired
    private Admin_UpdateSalaryService adminUpdateSalaryService;


    @PostMapping("/updateSalary")
    public String UpdateSalary(@RequestBody CSSCR csscr){
        if(csscr.getSalaryUpdate()>0) {
            adminUpdateSalaryService.RecordUpdateSalary(csscr.getCustomer_Service_ID(),csscr.getSalaryUpdate(),csscr.getChangeTime());
            return adminUpdateSalaryService.UpdateSalaryRise(csscr.getCustomer_Service_ID(), csscr.getSalaryUpdate());
        }
        else{
            adminUpdateSalaryService.RecordUpdateSalary(csscr.getCustomer_Service_ID(),csscr.getSalaryUpdate(),csscr.getChangeTime());
            return adminUpdateSalaryService.UpdateSalaryDown(csscr.getCustomer_Service_ID(), csscr.getSalaryUpdate());
        }
    }

    @GetMapping(value = "/ListSalaryUpdate")

    public List<CSSCR> ListSalaryUpdate(){

        return adminUpdateSalaryService.ListSalaryUpdate();
    }

}
